<?php

namespace App\Admin\Actions\MerchantAction;

use App\Models\Merchant;
use Brick\Math\RoundingMode;
use Illuminate\Http\Request;
use Encore\Admin\Facades\Admin;
use Encore\Admin\Actions\RowAction;
use App\Supports\Withdraw\Withdrawer;
use Illuminate\Database\Eloquent\Model;

class MerchantSetPassword extends RowAction
{
	public $name = '密码设置';

	public function handle(Model $merchant, Request $request)
	{
		/*if (!in_array(Admin::user()->id, [1,3])) {
			return $this->response()->error('无权操作')->refresh();
		}*/

		/**
		 * @var User $user
		 */


		$password = $request->get('password', '');

		if (!$password) {
			return $this->response()->error('请设置密码');
		}

		$password = bcrypt($password);

		$merchant = $merchant->update(['password'=>$password]);
		

		return $this->response()->success('密码设置成功')->refresh();
	}

	public function form()
	{

		$this->text('password', '密码')
			->rules('required');
	}
}
